<?php defined('SYSPATH') OR die('No direct access allowed.');

class Forum_Category_Controller extends Template_Controller {
	const ALLOW_PRODUCTION = FALSE;
	public $template = 'layouts/template_admin_forum';

	public function index(){
		url::redirect("forum/forum_category/listResultForumCategory");
	}

	public function forumCategoryForm(){
		$this->template->content = new View('forum/forum_category_create');
		$this->template->content->captcha = Captcha::factory();
		$this->template->title = '';

	}

	public function insertForumCategory(){
		
		if ($_POST){
			if (Captcha::valid($this->input->post('captcha_response'))){
				$forumCategory = new Forum_Category_Model();
				$forumCategory->name=$this->input->post("name");
				$forumCategory->user_id=1;
				$forumCategory->save();
				url::redirect("forum/forum_category/listResultForumCategory");
			}else{
				$this->template->content = new View('forum/forum_category_create');
				$this->template->content->captcha = Captcha::factory();
			}
		}else{
			$this->template->content = new View('forum/forum_category_create');
			$this->template->content->captcha = Captcha::factory();
		}
		$this->template->title = '';

	}

	public function listResultForumCategory(){
		$this->template->content = new View('forum/forum_category_listResult');
		$this->template->content->forum_categories=ORM::factory("forum_category")->find_all();
		$this->template->title = '';

	}
}
?>